#include <string>

#include <iostream>

#include "board.h"

int i,j,k;

/************************************************************************/


void Board::MakeBoard()
{


	for(i=0;i<6;i++)
	{


		for(j=0;j<13;j++)
		{
			board[i][j]=' ';
		}


	}



	for(k=0;k<13;k++)
	{
		board[6][k]='B';
	}


}

/************************************************************************/


Board::Board()


{
	Board::MakeBoard();
}

/************************************************************************/



bool Board::IsFull(int colChoice)
{
	if(board[0][colChoice]!=' ')

		return true;

	else

		return false;

}

/************************************************************************/


void Board::DrawBoard()
{

	system("cls");

	cout << "1  2  3  4  5  6  7" << endl;

	cout <<"___________________" << endl;


	for(i=0;i<6;i++)
	{

		for(j=0;j<8;j++)
		{

			cout << board[i][j];

			cout <<' ' <<' ';
		}

		cout<<endl<<endl;

	}

}

/************************************************************************/


void Board::DropPiece(int player, int colChoice)
{
	i=0;

	while(board[i+1][colChoice-1]==' ')

		i++;

	if(player==1)

		board[i][colChoice-1]='O';

	else

		board[i][colChoice-1]='X';

}

/************************************************************************/


bool Board::CheckForWinner()
{
	char checkChar=' ';

	char currentChar=' ';

	int count=0;

//Checks Horizontally
	for(i=0;i<6;i++)
	{

		for(j=0;j<8;j++)
		{	
			count=0;

			currentChar=board[i][j];

			checkChar=currentChar;

			if(checkChar=='O'||checkChar=='X')

				count++;

			currentChar=board[i][j+1];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i][j+2];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i][j+3];


			if(checkChar==currentChar)

				count++;


			if(count>3)

				return true;
		}

	}

/************************************************************************/

	//Checks Vertically
	for(i=0;i<6;i++)
	{

		for(j=0;j<8;j++)
		{	
			count=0;

			currentChar=board[i][j];

			checkChar=currentChar;

			if(checkChar=='O'||checkChar=='X')

				count++;

			currentChar=board[i+1][j];

			if(checkChar==currentChar)

				count++;

			currentChar=board[i+2][j];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i+3][j];


			if(checkChar==currentChar)

				count++;


			if(count>3)

				return true;
		}
	}


	//Checks Diagonally-Right

	for(i=0;i<6;i++)
	{
		for(j=0;j<8;j++)
		{	
			count=0;

			currentChar=board[i][j];

			checkChar=currentChar;


			if(checkChar=='O'||checkChar=='X')

				count++;

			currentChar=board[i+1][j+1];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i+2][j+2];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i+3][j+3];


			if(checkChar==currentChar)

				count++;


			if(count>3)

				return true;
		}
	}

/************************************************************************/

	//Checks Diagonally-Left
	for(i=0;i<6;i++)
	{
		for(j=0;j<8;j++)
		{	
			count=0;

			currentChar=board[i][j];

			checkChar=currentChar;


			if(checkChar=='O'||checkChar=='X')

				count++;

			currentChar=board[i+1][j-1];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i+2][j-2];


			if(checkChar==currentChar)

				count++;

			currentChar=board[i+3][j-3];


			if(checkChar==currentChar)

				count++;


			if(count>3)

				return true;
		}	

	}


	return false;

}

/************************************************************************/


bool Board::CheckForTie()
{
		//Checks if board is full (tie)
	for(i=0;i<1;i++)
	{
		int count=0;

		for(j=0;j<8;j++)
		{	
			char currentChar=board[0][j];


				if(currentChar!=' ')

					count++;

		}


		if(count>=7)

			return true;
	}

	return false;
}

/************************************************************************/

char Board::ReturnArrValue(int value, int colChoice)
{

	return board[value][colChoice];

}



/************************************************************************/



Board::~Board()
{

}